package com.ruoyi.project.tool.upload.controller;

import com.ruoyi.common.utils.AliyunOssUtil;
import com.ruoyi.common.utils.QiniuUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.tool.upload.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 上传图片
 */
@RestController
@RequestMapping("/upload")
public class UploadController extends BaseController {

    @Autowired
    private UploadService uploadService;

    /**
     * 上传图片
     * @param request
     * @param picFile
     * @param type 图片所属分类（goods、org）
     * @return
     */
    @RequestMapping(value = "/images")
    @ResponseBody
    public AjaxResult uploadImage2(MultipartHttpServletRequest request,
                                   @RequestParam(value = "file[]") MultipartFile[] picFile,
                                   @RequestParam(value = "type") String type) {
       return AjaxResult.success(uploadService.uploadImages(picFile,type));
    }

    /****
     * 删除图片
     * @param filePath
     * @return
     */
    @RequestMapping(value = "/delete",produces = "application/json; charset=utf-8")
    @ResponseBody
    public AjaxResult delImage(@RequestParam("filePath") String filePath){
        return uploadService.delImage(filePath);
    }

}
